package com.study.utils;

import com.google.common.collect.Lists;
import java.util.List;
import java.util.function.Supplier;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;

/**
 * @author zhuzi
 * 2022/6/27 14:23
 */
public class BeanJpaUtils {

    public static <S,T> List<T> copyList(List<S> sources,Supplier<T> supplier) {
        List<T> result = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(sources)) {
            sources.stream().forEach(item->{
                T t = supplier.get();
                BeanUtils.copyProperties(item,t);
                result.add(t);
            });
        }
        return result;
    }
}
